#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool canJump(vector<int>& nums)
    {
        int left = 0, right = 0, maxpos = 0, n = nums.size();
        while (left <= right)
        {
            if (maxpos >= n - 1) return true;
            for (int i = left; i <= right; i++)
            {
                maxpos = max(maxpos, i + nums[i]);
            }
            left = right + 1;
            right = maxpos;
        }
        return false;
    }
};

class Solution {
public:
    vector<int> diStringMatch(string s)
    {
        vector<int> ret;
        int left = 0, right = s.size();
        for (auto ch : s)
        {
            if (ch == 'I') ret.push_back(left++);
            else ret.push_back(right--);
        }
        ret.push_back(left);
        return ret;
    }
};
}